package com.briup.day23;

import java.io.*;

public class Test_Buffed {
    public static void main01(String[] args) throws Exception {
        //创建缓冲字节输入流
        //因为传入的参数就是输入流
//        0.0039秒
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream("01-Basic/src/dir/01.jpg"));
        //创建缓冲字节输出流
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("01-Basic/src/dir/02.jpg"));
        long start = System.currentTimeMillis();
        int len;
//        小数组3ms
        byte[] buf = new byte[1024];
        while ((len = bis.read(buf)) != -1) {
            bos.write(buf, 0, len);
        }
//        while ((len = bis.read()) != -1) {
//            bos.write(len);
//        }
        System.out.println("拷贝完成"+(System.currentTimeMillis()-start)+"ms");
        bis.close();
        bos.close();
    }
    /*使用原始流进行图片拷贝 6.1秒*/
    public static void main(String[] args) throws Exception{
//        /、创建字节输入流，（因为是缓冲）
        InputStream is = new FileInputStream("01-Basic/src/dir/01.jpg");
        OutputStream os = new FileOutputStream("01-Basic/src/dir/02.jpg");
        long start = System.currentTimeMillis();
        int len;
        byte[] buf = new byte[1024];
        while ((len = is.read(buf)) != -1) {
            os.write(buf, 0, len);//0.5秒
        }
//        while((len=is.read())!=-1){
//            os.write(len);
//        }
        long end = System.currentTimeMillis();
        System.out.println((end-start)+"拷贝哇完成时间");
        is.close();
        os.close();
    }
}
